package com.ruoyi.business.controller;

import com.ruoyi.business.domain.Bank;
import com.ruoyi.business.service.BankService;
import com.ruoyi.common.annotation.CheckUnique;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.TableDataInfo;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

 /**
 * 视图接口 : 银行信息
 * @Author  : ljq
 * @Created : 2025/10/4
 */
@RestController
@RequestMapping("/business/bank")
public class BankController extends BaseController {

    @Resource
    private BankService service;

    private static final String BASE_AUTH = "business:bank";
    private static final String LOG_TITLE = "银行信息#银行信息表 -- BankController";


    /**
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":list')")
    @GetMapping("/list")
    public TableDataInfo list(Bank entity, PageDomain pageDomain) {
        return TableDataInfo.build(
                service.listByCondition(entity, pageDomain)
        );
    }


    /**
     * 获取
     */
    @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":query')")
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable Long id) {
        Bank one = service.getById(id);
        return null == one ?  AjaxResult.noContent() : AjaxResult.success(one);
    }


     /**
      * 新增
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":add')")
     @Log(title = LOG_TITLE, businessType = BusinessType.INSERT)
     @CheckUnique(table = "t_bank", where = "bank_code or bank_name or bank_short_name",
             message = "编码")
     @PostMapping
     public AjaxResult add(@Validated @RequestBody Bank entity) {
         return toAjax(service.save(entity));
     }


     /**
      * 修改
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":edit')")
     @Log(title = LOG_TITLE, businessType = BusinessType.UPDATE)
     @CheckUnique(excludeId = "id", table = "t_bank", where = "bank_code or bank_name or bank_short_name",
             message = "{bank_code:银行编码, bank_name:银行名称， bank_short_name:银行简称}")
     @PutMapping
     public AjaxResult edit(@Validated @RequestBody Bank entity) {
         return toAjax(service.updateById(entity));
     }


     /**
      * 删除
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":remove')")
     @Log(title = LOG_TITLE, businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(service.removeByIds(Arrays.asList(ids)));
     }


}